package com.itheima.googleplay9.adapter;

import android.graphics.Matrix;
import android.media.Image;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.itheima.googleplay9.api.Url;
import com.itheima.googleplay9.global.GooglePlayApp;
import com.itheima.googleplay9.global.ImageLoaderOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

import uk.co.senab.photoview.PhotoView;


/**
 * Created by lxj on 2016/5/27.
 */
public class ImageScaleAdapter  extends PagerAdapter{
    private ArrayList<String> urlList;

    public ImageScaleAdapter(ArrayList<String> urlList) {
        this.urlList = urlList;
    }

    @Override
    public int getCount() {
        return urlList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
//        ImageView imageView = new ImageView(GooglePlayApp.context);
        PhotoView photoView = new PhotoView(GooglePlayApp.context);

        //加载图片
        ImageLoader.getInstance().displayImage(Url.IMAGE_PREFIX+urlList.get(position),
                photoView, ImageLoaderOptions.options);

        //将ImageVIew添加到ViewPager中
        container.addView(photoView);

        return photoView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
        container.removeView((View) object);
    }

}
